package com.bdqn.vueboot.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;

import java.time.LocalDateTime;

/**
 * 原数据对象处理器
 */
@Configuration
@Slf4j
public class MyMetaObjecthandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        try {
            metaObject.setValue("creationId", BascText.getCarId());
            metaObject.setValue("creationTime", LocalDateTime.now());
//            metaObject.setValue("timeApplication", LocalDateTime.now());
        } catch (Exception e) {
            throw new CustomException("请重新登录！");
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        try {
            metaObject.setValue("updateId", BascText.getCarId());
            metaObject.setValue("updateTime", LocalDateTime.now());
//            metaObject.setValue("timeApplication", LocalDateTime.now());
        } catch (Exception e) {
            throw new CustomException("请重新登录！");
        }
    }
}
